from web import db


class Headline(db.Model):

    __tablename__ = "headline"
    key = db.Column(db.String(32), primary_key=True)
    sid  = db.Column(db.String(6))
    date = db.Column(db.String(10))
    content = db.Column(db.Text)
    chg = db.Column(db.Float(precision=2))

    def __init__(self, key=None, sid=None, date=None, content=None, chg=None):
        self.key = key
        self.sid = sid
        self.date = date
        self.content = content
        self.chg = chg


class EMComment(db.Model):
    
    __tablename__ = "emcomments"

    key = db.Column(db.String(32), primary_key=True)
    sid  = db.Column(db.String(6))
    title = db.Column(db.Text)
    read_count = db.Column(db.Integer)
    comment_count = db.Column(db.Integer)
    chg = db.Column(db.Float(precision=2))
    publish_date = db.Column(db.String(10))
    publish_time = db.Column(db.String(8))
    last_update = db.Column(db.String(11))

    def __init__(self, key=None, sid=None, publish_date=None, title=None,
        read_count=None, comment_count=None, chg=None, publish_time=None, 
        last_update=None):

        self.key = key
        self.sid = sid
        self.publish_date = publish_date
        self.publish_time = publish_time
        self.last_update = last_update
        self.title = title
        self.read_count = read_count
        self.comment_count = comment_count
        self.chg = chg


class News(db.Model):

    __tablename__ = "news"

    key   = db.Column(db.String(32), primary_key=True)
    date  = db.Column(db.String(10), index=True)
    time  = db.Column(db.String(8))
    sid   = db.Column(db.String(6),  index=True)
    name  = db.Column(db.String(10))
    title = db.Column(db.Text)
    body  = db.Column(db.Text)
    fetched = db.Column(db.String(19))
    
    def __init__(self, **kwargs):
        if kwargs:
            for k, v in kwargs.iteritems():
                setattr(self, k, v)